#include <stdio.h>
#include <stdlib.h>

typedef int ElemType;
typedef struct LNode {
    ElemType data;
    LNode *next;
} LNode, *LinkList;

void List_head_insert(LinkList &L) {
    L = (LinkList) malloc(sizeof(LNode));//申请头指针
    ElemType num;
    LinkList q, p;
    q = L;//将头结点的位置赋给头指针
    scanf("%d", &num);
    while (num != 9999) {
        p = (LinkList) malloc(sizeof(LNode));
        p->data = num;
        q->next = p;//将新结点的位置赋给尾结点的next指针
        q = p;//将指针地址赋给下一个指针
        scanf("%d", &num);
    }
    p->next = NULL;//将尾指针的数据域置为NULL
}

//链表输出
void Print_list(LinkList L) {
    L = L->next;
    while (L) {
        printf("%3d ", L->data);
        L = L->next;
    }
}

//尾插法新建链表
int main() {
    LinkList L;
    List_head_insert(L);
    Print_list(L);
    return 0;
}
